package com.mumu.android.tcp.data;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @Author: MuMu
 * @Date: 2025/3/8 10:38
 */
public class Configuration {
    private final SharedPreferences  sharedPreferences;
    private final SharedPreferences.Editor editor;

    private final String Key_TCP_IP = "TCP_IP", Key_TCP_PORT = "TCP_PORT";

    public Configuration(Context context) {
        sharedPreferences = context.getSharedPreferences("ip_config", 0);
        editor = sharedPreferences.edit();
    }


    public void saveHost(HostInfo hostInfo){
        editor.putString(Key_TCP_IP, hostInfo.getHostName());
        editor.putInt(Key_TCP_PORT, hostInfo.getPort());
        editor.apply();
    }

    public HostInfo getHost(){
        String ipaddress = sharedPreferences.getString(Key_TCP_IP,"");
        int port = sharedPreferences.getInt(Key_TCP_PORT,-1);
        return new HostInfo(ipaddress, port);
    }



}
